<?php
defined('BASEPATH') OR exit('No direct script access allowed');
//角色管理
class Role extends CommonController {

	function __construct(){
		
		parent::__construct();
		$this->load->model('Index/RoleModel','CurModel');
		
	}
	
	
	//start
	/**
	* @name 获取列表
	* @param page ture char 页面
	* @param size ture char 数量
	* @return 成功返回1
	*/
	//end
	function get_list(){
		$user_id = $this->user_id;
		
		$filter = array('name');
		$arr = array(
			'filter'=>$filter
		);
		
		$result = parent::_get_list($arr);
		if(!$result){
			$this->err_out($this->getError());
		}

		
		$this->data_out($result);
	}
	
	//start
	/**
	* @name 获取所有
	* @return 成功返回1
	*/
	//end
	function get_all(){
		$user_id = $this->user_id;
		
		$list = $this->CurModel->getAll();

		
		$this->data_out($list);
	}
	
	function info_out($info){
		
		return $info;
	}
	
	//start
	/**
	* @name 获取信息
	* @param id ture char ID
	* @return 成功返回1
	*/
	//end
	function get_info(){
		$user_id = $this->user_id;
		
		$result = parent::_get_info();
		if(!$result){
			$this->err_out($this->getError());
		}
		
		$this->data_out($result);
	}
	
	//start
	/**
	* @name 获取信息
	* @param id ture char ID
	* @return 成功返回1
	*/
	//end
	function save(){
		
		if(!$this->check_priv('role_update|role_add')){
			$this->err_out(LANG_NOPRIV);
		}
		
		$filter = array(
			'name'=>'名称不能为空'
		);
		$post = array('name','info','privs');
		$farr = array(
			'post'=>$post,
			'filter'=>$filter
		);
		
		$result = parent::_save($farr);
		if(!$result){
			$this->err_out($this->getError());
		}
		
		$this->add_log("保存角色【{$result['id']}】信息",'role');
		
		$this->data_out($result);
	}
	


	
	//start
	/**
	* @name 删除
	* @param id ture int ID
	* @return 成功返回1
	*/
	//end
	function del(){
		
		if(!$this->check_priv('role_del')){
			$this->err_out(LANG_NOPRIV);
		}
		
		$result = parent::_del();
		if(!$result){
			$this->err_out($this->getError());
		}
		
		
		$this->add_log("删除角色【{$result}】信息",'role');
		$this->data_out($result);
		
	}
	//start
	/**
	* @name 获取权限列表
	* @return 成功返回1
	*/
	//end
	function get_priv_list(){
		$this->load->dmodel('privs','privs');
		
		$list = $this->privs->getAll("parent_id=0");
		foreach($list as $key=>$val){
			$list[$key]['children'] = $this->privs->getAll("parent_id='{$val['id']}'");
			
		}
		
		$this->data_out($list);
	}
	
}
